package com.twu.biblioteca;


public class Book implements Resource {

    private final String title;
    private String author;
    private String isbn;

    public Book(String title, String author, String isbn) throws RuntimeException{

        if(title != null && author != null && isbn != null){
        this.title = title;
        this.author = author;
        this.isbn = isbn;
        }else{
            throw new RuntimeException(Messages.INCOMPLETE_BOOK_INFOR);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Book book = (Book) o;

        if (author != null ? !author.equals(book.author) : book.author != null) return false;
        if (isbn != null ? !isbn.equals(book.isbn) : book.isbn != null) return false;
        if (title != null ? !title.equals(book.title) : book.title != null) return false;

        return true;
    }


    @Override
    public int hashCode() {
        int result = title != null ? title.hashCode() : 0;
        result = 31 * result + (author != null ? author.hashCode() : 0);
        result = 31 * result + (isbn != null ? isbn.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Title: " + title +", Author: " + author + ", ISBN: "+isbn;
    }

    @Override
    public String display() {
        return "Title: " + title +", Author: " + author + ", ISBN: "+isbn;

    }

    @Override
    public boolean titleMatches(String title) {
        return this.title.equals(title);
    }

}
